import http from '@/utils/http'
import { Product } from '@/pojo/dto/Product'

//查询不同状态商品
export function productListApi(condition) {
  // console.log('productListApi请求传参:'+condition)
  return http({
    url: 'product/product-list/' + condition,
  });
}
//统计不同状态的商品数量
export function productCountNumberApi() {
  // console.log('productCountNumberApi请求传参:')
  return http({
    url: 'product/product-count'
  })
}

//删除商品
export function delProductApi(pid) {
  // console.log('delProductApi请求传参:'+pid)
  return http({
    url: 'product/del-product/' + pid,
    method: 'POST',
  });
}
//恢复商品
export function recoverProductApi(pid) {
  // console.log('recoverProductApi请求传参:'+pid)
  return http({
    url: 'product/recover-product/' + pid,
    method: 'POST',
  });
}
//修改商品
export function updateProductApi({ productId, status, sort, name, price, number }) {
  // console.log('updateProductApi请求传参:')
  return http({
    url: 'product/update-product/',
    method: 'POST',
    data: {
      productId: productId,
      status: status,
      sort: sort,
      name: name,
      price: price,
      number: number,
    }
  });
}
//批量处理商品（上下架、库存，删除）
export function updateBatchProductApi({ productIdList, status, number, isExist }) {
  // console.log('updateBatchProductApi请求传参:')
  return http({
    url: 'product/update-batch-product/',
    method: 'POST',
    data: {
      productIdList: productIdList,
      status: status,
      number: number,
      isExist: isExist
    }
  });
}
//添加商品
export function addProductApi(addProduct:Product) {
  console.log('addProductApi请求传参:')
  console.log(addProduct)
  return http({
    url: 'product/add-product',
    method: 'POST',
    data: addProduct,
  });
}
//编辑商品-数据回显
export function productInfoApi(pid: number) {
  // console.log('productInfoApi请求传参:')
  // console.log(pid)
  return http({
    url: 'product/product-info/' + pid,
  });
}
//编辑商品
export function updateProductInfoApi(updateProduct: Product) {
  // console.log('updateProductInfoApi请求传参:')
  // console.log(updateProduct.imgs)
  return http({
    url: 'product/update-product-info',
    method: 'POST',
    data: updateProduct,
  });
}
//---------------------------------------------------------------------------商品分类-----------------------------------------------

//分类
export function classify1ListApi() {
  return http({
    url: 'classify1/classify1-list'
  })
}
//分类名列表
export function classify1ListNameApi() {
  return http({
    url: 'classify1/classify1-list-name'
  })
}

//---------------------------------------------------------------------------商品扩展-----------------------------------------------

//所有规格列表
export function specificationListApi() {
  return http({
    url: 'specification/specification-list'
  })
}


//商品对应规格列表
export function specificationByProductIdListApi(productId: String) {
  return http({
    url: 'specification/specifications-by-product-id/' + productId
  })
}

//商品对应规格更新
export function updateSpecificationByProductIdListApi(specificationId: String, price: String, number: String,productId:String) {
  
    return http({
      url: 'specification/update-specification',
      method: 'PUT',
      data: {
        id: specificationId,
        number: number,
        price: price,
        productId:productId
      
      }
    })
}

//属性列表
export function propertyListApi() {
  return http({
    url: 'property/property-list'
  })
}
//加料列表
export function chargeListApi() {
  return http({
    url: 'charge/charge-list'
  })
}
//单位列表
export function unitListApi() {
  return http({
    url: 'unit/unit-list'
  })
}

//单位名称列表
export function unitListNameApi() {
  return http({
    url: 'unit/unit-list-name'
  })
}